package xyz.ddlnt.serviceusr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import xyz.ddlnt.commonutil.constant.FieldConstants;
import xyz.ddlnt.model.entity.Technology;
import xyz.ddlnt.model.vo.ExamQuestionIntroVO;
import xyz.ddlnt.model.vo.TechnologyInfoVO;
import xyz.ddlnt.serviceusr.mapper.TechnologyMapper;
import xyz.ddlnt.serviceusr.service.TechnologyService;

import java.util.List;
import java.util.Objects;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/5 1:33
 */
@Slf4j
@Service
public class TechnologyServiceImpl extends ServiceImpl<TechnologyMapper, Technology> implements TechnologyService {

    @Resource
    private TechnologyMapper technologyMapper;


    @Override
    public List<ExamQuestionIntroVO> listExamQuestionIntroVO(Long technologyId) {

        return List.of();
    }

    @Override
    public List<TechnologyInfoVO> selectByCategoryId(Long categoryId) {
        LambdaQueryWrapper<Technology> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(!Objects.equals(categoryId, FieldConstants.ALL_CATEGORIES), Technology::getCategoryId, categoryId)
                .select(Technology::getId, Technology::getTechnologyName, Technology::getTechnologyIcon, Technology::getTechnologyIntroduce);
        List<Technology> technologies = technologyMapper.selectList(queryWrapper);
        // 封装成 TechnologyInfoVOS
        return technologies.stream().map(technology -> {
            TechnologyInfoVO technologyInfoVO = new TechnologyInfoVO();
            BeanUtils.copyProperties(technology, technologyInfoVO);
            return technologyInfoVO;
        }).toList();
    }

    @Override
    public TechnologyInfoVO selectByTechnologyId(Long technologyId) {
        LambdaQueryWrapper<Technology> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Technology::getId, technologyId)
                .select(Technology::getId, Technology::getTechnologyName, Technology::getTechnologyIcon, Technology::getTechnologyIntroduce);
        Technology technology = technologyMapper.selectOne(queryWrapper);
        TechnologyInfoVO technologyInfoVO = new TechnologyInfoVO();
        BeanUtils.copyProperties(technology, technologyInfoVO);
        return technologyInfoVO;
    }


}
